package com.xyd.servlet;

import com.xyd.biz.UserBiz;
import com.xyd.biz.impl.UserBizImpl;
import com.xyd.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/UserLoginServlet")
public class UserLoginServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //第一次的修改
		//李四修改的内容
        String name = request.getParameter("username");
        String pwd = request.getParameter("password");

        UserBiz userBiz = new UserBizImpl();
        User u = new User();
        u.setName(name);
        u.setPwd(pwd);
        User user = userBiz.userLogin(u);

        if (user != null) {
            request.getSession().setAttribute("user", user);
            request.getRequestDispatcher("succ.jsp").forward(request, response);
        } else {
            response.sendRedirect("login.html");
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
